<template>
  <el-select v-model="value" placeholder="选择一个密码找回问题" @change="optionChange">
    <el-option v-for="item in optionLists" :key="item.id" :label="item.label" :value="item.value">
    </el-option>
  </el-select>
</template>

<script>
export default {
  props:{
    isValueNull:{
      type:Boolean
    }
  },
  data() {
    return {
      value: "",
      optionLists:[]
    };
  },
  watch:{
    isValueNull(){
      this.value = '';
    }
  },
  methods:{
    optionChange(val){
      let valID;
      this.optionLists.forEach((el,i)=>{
        if(el.value === val){
          valID = el.id;
        }
      });
      this.$emit('pwdQuestionChange',valID);
    }
  },
  mounted(){
    this.axios
      .get("user/getObtainUserAnswerList")
      .then(res => {
        if (res.data.status) {
          let root = [];
          for (var i in res.data.data){
              root.push(res.data.data[i]);
          }
          this.optionLists = root;  
        } else {
          this.log(res.data.message);
        }
      })
      .catch(err => {
        this.log(err);
      });
  }
};
</script>

<style lang="less">
@import url(../assets/css/selection.less);
</style>
